var path = "../";
var path = "../";

var lineList = [];
var barList = [];
var trade = [];
var standbyPlay = [];
var date = [];
var myChart = echarts.init(document.getElementById('main'));
//异步加载数据

myChart.showLoading();
$.ajax({
    type: "post",
    async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
    url: path + "advPlay/getTotalPlayVolume",    //请求发送到getTotalPlayVolume处
    data: {day: 1},
    dataType: "json",        //返回数据形式为json
    success: function (result) {
        //请求成功时执行该函数内容，result即为服务器返回的json对象
        if (result) {
            lineList = [];
            trade = [];
            standbyPlay = [];
            barList = [];
            if ("" != result && result != null) {
                if (result.total != null) {
                    for (var i = 0; i < result.total.length; i++) {
                        lineList.push(result.total[i].tigLineNum);
                    }
                }
                if (result.contract != null) {
                    for (var i = 0; i < result.contract.length; i++) {
                        trade.push(result.contract[i].tigLineNum);
                    }
                }
                if (result.standby != null) {
                    for (var i = 0; i < result.standby.length; i++) {
                        standbyPlay.push(result.standby[i].tigLineNum);
                    }
                }
                if (result.realTime != null) {
                    for (var i = 0; i < result.realTime.length; i++) {
                        barList.push(result.realTime[i].tigLineNum);
                    }
                }
            }
            myChart.hideLoading();
            var option = {
                title: {
                    text: '广告播放量'
                },
                tooltip: {},
                legend: {
                    data: ['总播放量', '待机播放量', '合同竞价播放量', '实时竞价播放量']
                },
                xAxis: {
                    data: ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00",
                        "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"]
                },
                dataZoom: [{
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    left: '9%',
                    bottom: -5,
                    start: 0,
                    end: 90 //初始化滚动条
                }],
                yAxis: {},
                toolbox: {
                    show: true,
                    orient: 'horizontal',
                    showTitle: true,
                    feature: {
                        magicType: {
                            type: ['line']
                        },
                        saveAsImage: {
                            type: 'png',
                            show: true,
                            title: '保存为图片',
                        },
                        restore: {show: true}
                    }
                },
                series: [
                    {
                        name: '总播放量',
                        type: 'line',
                        data: lineList
                    },
                    {
                        name: '待机播放量',
                        type: 'line',
                        data: standbyPlay
                    },
                    {
                        name: '合同竞价播放量',
                        type: 'line',
                        data: trade
                    },
                    {
                        name: '实时竞价播放量',
                        type: 'line',
                        data: barList
                    }
                ]
            };
            myChart.setOption(option);
        }
    },
    error: function (errorMsg) {
        //请求失败时执行该函数
        alert("图表请求数据失败!");
        myChart.hideLoading();
    }
});

myChart.showLoading();

function toDayClick(day) {
    $.ajax({
        type: "post",
        async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
        url: path + "advPlay/getTotalPlayVolume",    //请求发送到getTig处
        data: {day: day},
        dataType: "json",        //返回数据形式为json
        success: function (result) {
            //请求成功时执行该函数内容，result即为服务器返回的json对象
            if (result) {
                lineList = [];
                date = [];
                if ("" != result && result != null) {
                    lineList = [];
                    trade = [];
                    standbyPlay = [];
                    barList = [];
                    if ("" != result && result != null) {
                        if (result.total != null) {
                            for (var i = 0; i < result.total.length; i++) {
                                lineList.push(result.total[i].tigLineNum);
                            }
                        }
                        if (result.contract != null) {
                            for (var i = 0; i < result.contract.length; i++) {
                                trade.push(result.contract[i].tigLineNum);
                            }
                        }
                        if (result.standby != null) {
                            for (var i = 0; i < result.standby.length; i++) {
                                standbyPlay.push(result.standby[i].tigLineNum);
                            }
                        }
                        if (result.realTime != null) {
                            for (var i = 0; i < result.realTime.length; i++) {
                                barList.push(result.realTime[i].tigLineNum);
                            }
                        }
                    }
                }
                if (day == 1) {
                    date = ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00",
                        "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"];
                } else {
                    if (result.contract != null) {
                        for (var i = 0; i < result.contract.length; i++) {
                            date.push(result.contract[i].tigHour);
                        }
                    }
                }
            }
            myChart.hideLoading();
            var option = {
                title: {
                    text: '广告播放量'
                },
                tooltip: {},
                legend: {
                    data: ['总播放量', '待机播放量', '合同竞价播放量', '实时竞价播放量']
                },
                xAxis: [
                    {
                        data: date
                    }
                ],
                dataZoom: [{
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    left: '9%',
                    bottom: -5,
                    start: 0,
                    end: 90 //初始化滚动条
                }],
                yAxis: {},
                toolbox: {
                    show: true,
                    orient: 'horizontal',
                    showTitle: true,
                    feature: {
                        magicType: {
                            type: ['line']
                        },
                        saveAsImage: {
                            type: 'png',
                            show: true,
                            title: '保存为图片',
                        },
                        restore: {show: true}
                    }
                },
                series: [
                    {
                        name: '总播放量',
                        type: 'line',
                        data: lineList
                    },
                    {
                        name: '待机播放量',
                        type: 'line',
                        data: standbyPlay
                    },
                    {
                        name: '合同竞价播放量',
                        type: 'line',
                        data: trade
                    },
                    {
                        name: '实时竞价播放量',
                        type: 'line',
                        data: barList
                    }
                ]
            };
            myChart.clear();
            option.series[0].data = lineList;
            option.xAxis[0].data = date;
            myChart.setOption(option);
        },
        error: function (errorMsg) {
            //请求失败时执行该函数
            alert("图表请求数据失败!");
            myChart.hideLoading();
        }
    });
};

function reboot() {
    window.location.reload();
}

